const app = getApp()
const db = wx.cloud.database()

Page({
  data: {
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    modalStatus: false,
    gridCol: 3,
    skin: false,
    secondHandList: [],
    percentageList: ['几乎全新', '9成新', '8成新', '6成新', '比较旧'],
    iconList: [{
      icon: 'goodsfill',
      color: 'red',
      badge: 5,
      name: '二手交易',
      navigateUrl: '/pages/publish-lists/secondhand/secondhand'
    }, {
      icon: 'notificationfill',
      color: 'orange',
      badge: 0,
      name: '失物招领',
      // navigateUrl: '/pages/publish-lists/lost/lost'
    }, {
      icon: 'infofill',
      color: 'yellow',
      badge: 0,
      name: '兼职资讯'
    }, {
      icon: 'lightfill',
      color: 'olive',
      badge: 0,
      name: '快递代取'
    }, {
      icon: 'activityfill',
      color: 'cyan',
      badge: 0,
      name: '校园活动'
    }, {
      icon: 'upstagefill',
      color: 'blue',
      badge: 0,
      name: '敬请期待'
    }]
  },
  onLoad: function() {
    db.collection('secondhand').orderBy('createTime', 'desc').limit(3).get().then(res => {
      console.log(res)
      this.setData({
        secondHandList: res.data
      })
    }).catch(err => {
      console.log(err)
    })
  },
  onShow: function() {
    if (typeof this.getTabBar === 'function' &&
      this.getTabBar()) {
      console.log('设置选中项 0')
      this.getTabBar().setData({
        selected: 0
      })
    }
  },

  onHide(){
    console.log('index is hidden')
    let bar = this.getTabBar()
    console.log('bar is', bar)
  },

  cardSwiper(e) {
    this.setData({
      cardCur: e.detail.current
    })
  },

  onNavigate(e){
    const url = e.currentTarget.dataset.navigateurl
    wx.navigateTo({
      url
    })
  },

  goSecondHandDetail(e){
    let goodId = e.currentTarget.dataset.goodid
    wx.navigateTo({
      url:  `/pages/publish-lists/secondhand/detail/detail?goodId=${goodId}`,
    }) 
  }
})